﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HydrogenAtom4 {
    class SphericalCoordinates {
        private readonly double mr;
        private readonly double mθ;
        private readonly double mφ;

        public double r { get { return mr; } }
        public double θ { get { return mθ; } }
        public double φ { get { return mφ; } }

        public SphericalCoordinates(double r, double θ, double φ) {
            mr = r;
            mθ = θ;
            mφ = φ;
        }

        public static SphericalCoordinates FromXYZ(double x, double y, double z) {
            double r = Math.Sqrt(x * x + y * y + z * z);
            double θ = 0.0f;
            double φ = 0.0f;
            if (!Util.AlmostZero(r)) {
                θ = Math.Acos(z / r);
            }
            if (!Util.AlmostZero(x) || !Util.AlmostZero(y)) {
                φ = Math.Atan2(y, x);
            }
            return new SphericalCoordinates(r, θ, φ);
        }
    };
}
